/**
 * class which helps with saving data to files
 */
package common;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

/**
 * @author vladimir
 * 
 */
public class FSave {
	/** Function saves target to file fName on folder path **/
	public static void fSave(String path, String fName, double target) {

		try {
			File f = new File("./");
			boolean success = (new File(f.getCanonicalPath() + path)).mkdirs();// Create
																				// folder
			FileWriter outFile = new FileWriter(f.getCanonicalPath() + path
					+ "/" + fName);
			PrintWriter out = new PrintWriter(outFile);
			out.println(target);
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	public static void fSave(String path, String fName, StringBuilder[] target) {

		try {
			File f = new File("./");
			boolean success = (new File(f.getCanonicalPath() + path)).mkdirs();// Create
																				// folder
			FileWriter outFile = new FileWriter(f.getCanonicalPath() + path
					+ "/" + fName);
			PrintWriter out = new PrintWriter(outFile);
			for (int i = 0; i < target.length; i++) {
				out.println(target[i]);
			}
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	public static void fSave(String path, String fName, double[] target) {

		try {
			File f = new File("./");
			boolean success = (new File(f.getCanonicalPath() + path)).mkdirs();// Create
																				// folder
			FileWriter outFile = new FileWriter(f.getCanonicalPath() + path
					+ "/" + fName);
			PrintWriter out = new PrintWriter(outFile);
			for (int i = 0; i < target.length; i++) {
				out.println(target[i]);
			}
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

}
